﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PdfLibrary
{
    public class PdfArray : List<IPdfObject>, IPdfObject
    {
        public bool LoadFromReader(PdfReader reader, bool throwException)
        {
            if (!reader.TryReadToken("["))
                if (throwException) throw new PdfParsingException(reader, "Array start tag ([) not found!");
                else return false;

            // because of nested arrays, we delete this instance from the singleton dictionary
            SingletonDictionary.Reset<PdfArray>();

            while (!reader.TryReadToken("]"))
            {
                reader.PositionCheck("searching for array end");

                Add(PdfObject.CreateFromReader(reader));
            }

            return true;
        }
    }
}
